<?php
class My_View_Helper_MyFlashMessenger extends Zend_View_Helper_Abstract
{
	private $_types = array(
	My_Controller_Action_Helper_MyFlashMessenger::ERROR,
	My_Controller_Action_Helper_MyFlashMessenger::WARNING,
	My_Controller_Action_Helper_MyFlashMessenger::NOTICE,
	My_Controller_Action_Helper_MyFlashMessenger::SUCCESS
	);
	public function myFlashMessenger()
	{
		$flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('MyFlashMessenger');
		$html = '';
		foreach ($this->_types as $type) {
			$messages = $flashMessenger->getMessages($type);
			if (!$messages){
				$messages = $flashMessenger->getCurrentMessages($type);
			}
			if ($messages) {

				$html .= '<div class="messages"><ul class="' . $type . '-msg">';
				foreach ( $messages as $message ) {
					$html.= '<li>';
					$html.= $message->message;
					$html.= '</li>';
				}
				$html .= '</ul></div>';
			}
		}

		return $html;
	}
	
	public function hasMessages( $type )
	{    
	    $flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('MyFlashMessenger');
	    
	    $messages = $flashMessenger->getMessages($type);
		if ( ! $messages ){
			$messages = $flashMessenger->getCurrentMessages($type);
		}
		
		return $messages ? true : false;
	    
	}
	
    public function hasError()
	{
	    return $this->hasMessages( My_Controller_Action_Helper_MyFlashMessenger::ERROR );
	}
	
    public function hasSuccess()
	{
	    return $this->hasMessages( My_Controller_Action_Helper_MyFlashMessenger::SUCCESS );
	}
	
    public function hasWarning()
	{
	    return $this->hasMessages( My_Controller_Action_Helper_MyFlashMessenger::WARNING );
	}
   
    public function hasNotice()
	{
	    return $this->hasMessages( My_Controller_Action_Helper_MyFlashMessenger::NOTICE );
	}
	
}